@model CleverCMS.Cms.Data.Entities.Role

@section TitleContent
{
    @((Model != null && Model.RoleId != 0) ? "Update Role" : "New Role")
}

@section HeadContent
{
    <script type="text/javascript">
        function successSave(e) {
            if (e.success) {
                $("#failureResult").hide();
                $("#successResult").show().fadeOut(5000);
            } else {
                $("#errortext").html(e.error);
                $("#failureResult").fadeIn(1000);
            }
        }
        function failureSave() {
            $("#failureResult").show().fadeIn(700);
        }

        $(document).ready(function () {
            $("button[type=submit]").on("click", function () {
                $("html, body").animate({ scrollTop: 0 }, "slow");
            });
        });
    </script>
}

<div class="widget green">
    <div class="widget-title">
        <h4><i class="icon-reorder"></i> Role</h4>
    </div>
    <div class="widget-body">
        
        <div id="failureResult" class="alert alert-block alert-error" style="display: none">
            <h4 class="alert-heading">Error!</h4>
            <p id="errortext">
            </p>
        </div>

        <div class="alert alert-block alert-success" style="display: none" id="successResult">
            <h4 class="alert-heading">Success!</h4>
            <p>
                Items was successfully saved.
            </p>
        </div>

        @if (!ViewData.ModelState.IsValid)
        {
            <h4 class="alert_error">@Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.")</h4>
        }
        <div class="module_content">
            @using (Ajax.BeginForm("Edit", "Role", new AjaxOptions { HttpMethod = "POST", OnFailure = "failureSave", OnSuccess = "successSave" }, new { id = "editUserForm", @class = "search_form general_form" }))
            {
                @Html.HiddenFor(x => x.RoleId)
                <label>Title:</label>
                <div>
                    @Html.TextBoxFor(x => x.RoleName, new { @class = "text large", @style = "width: 30%" })
                    @Html.ValidationMessageFor(x => x.RoleName)
                </div>
                <button type="submit" class="btn btn-success" name="save_role"><i class="icon-ok icon-white"></i> Save</button>
                <button class="btn btn-inverse" onclick="resetFields(this); return false;"><i class="icon-refresh icon-white"></i> Reset</button>
                <button class="btn btn-inverse" onclick="history.back()"><i class="icon-ban-circle icon-white"></i> Back</button> 
            }
        </div>
    </div>
</div>